package com.kk.netty.nio.file;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class TestCopyMultDirectory {
    public static void main(String[] args) throws IOException {
        String source = "j:\\test";
        String target = "j:\\testTemp";
        long start = System.currentTimeMillis ();

        Files.walk (Paths.get (source)).forEach (path -> {
            try {
                String targetName = path.toString ( ).replace (source, target);
                // 如果是目录
                if (Files.isDirectory (path)){
                    Files.createDirectories (Paths.get (targetName));
                }
                // 如果是文件
                else if (Files.isRegularFile (path)){
                    Files.copy (path,Paths.get (targetName));
                }
            } catch (Exception e) {
                e.printStackTrace ( );
            }
        });

        long end = System.currentTimeMillis();
        System.out.println(end - start);
    }
}
